<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../assets/js/vue.js"></script>
    <link rel="stylesheet" href="../assets/css/index.css"/>
</head>
<body>
<h1>实例事件</h1>
<hr>
<div id="app">
    <p>{{a}}</p>
    <p>
        <button @click="jia">+</button>
        <button onclick="jian()">-</button>
    </p>
    <p>
        <button onclick="off()">del</button>
    </p>

</div>

<script>
    var vm = new Vue({
        el: '#app',
        data: {
            a: 1
        },
        methods: {
            jia: function () {
                this.a++
            }
        }
    })

//    vm.$once('jian', function (num) {
    vm.$on('jian', function (num) {
        console.log('执行了减')
        this.a -= num
    })

    function jian(){
        vm.$emit('jian','2')
    }

    function off(){
        vm.$off('jian')
    }
</script>
</body>
</html>